home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr05 / ddeexamp.zip / DDEEXEC.C < prev    next >
C/C++ Source or Header  |  1993-07-08  |  3KB  |  171 lines

  1. /*
  2.     ddeexec.c
  3.  
  4.     Bogus DDE Execute demonstration server
  5.  
  6.     Another fine Herman Rodent production
  7.  
  8. */
  9.  
  10. #include "ddeexec.h"
  11.  
  12. //
  13. // global data
  14. //
  15.  
  16. char *szAppName = "DdeExec";        // DDE Server name
  17. HINSTANCE hInst;                    // app instance
  18. HWND hwndMain;                      // main window handle
  19.  
  20. //
  21. // local functions
  22. //
  23.  
  24. static void Command(HWND hWnd, WPARAM wParam, LPARAM lParam);
  25. static void Paint(HWND hWnd, HDC hDC);
  26.  
  27. //
  28. // Entry point
  29. //
  30.  
  31. int PASCAL WinMain(HINSTANCE hInstance,
  32.                    HINSTANCE hPrevInstance,
  33.                    LPSTR lpszCmdLine,
  34.                    int cmdShow)
  35. {
  36.     MSG msg;
  37.  
  38.     hInst = hInstance;
  39.  
  40.     //
  41.     // We only allow one instance
  42.     //
  43.  
  44.     if (hPrevInstance) {
  45.  
  46.         BringWindowToTop(FindWindow(szAppName, NULL));
  47.         return 1;
  48.     }
  49.  
  50.     //
  51.     // Do the initialization
  52.     //
  53.  
  54.     if (!Init(hInstance, cmdShow)) {
  55.         return 1;
  56.     }
  57.  
  58.     //
  59.     // Check for messages from Windows and process them.
  60.     // If no messages, perform some idle function
  61.     // 
  62.  
  63.     while (GetMessage(&msg, NULL, 0, 0)) {
  64.  
  65.         TranslateMessage(&msg);
  66.         DispatchMessage(&msg);
  67.     }
  68.  
  69.     return (msg.wParam);
  70. }
  71.     
  72. //
  73. // main window message handler
  74. //
  75.  
  76. LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  77. {
  78.     PAINTSTRUCT ps;
  79.     RECT rc;
  80.  
  81.     switch(msg) {
  82.     case WM_CREATE:
  83.         break;
  84.  
  85.     case WM_SIZE:
  86.  
  87.         //
  88.         // update the rectangle info we keep for painting
  89.         //
  90.  
  91.         rc.left = rc.top = 0;
  92.         rc.right = LOWORD(lParam) - 1;
  93.         rc.bottom = HIWORD(lParam) * 2 / 3 - 1;
  94.  
  95.         if (hwndStatus) {
  96.  
  97.             //
  98.             // The status window occupies the lower half of the
  99.             // main window
  100.             //
  101.  
  102.             MoveWindow(hwndStatus, 
  103.                        0, rc.bottom + 1,
  104.                        LOWORD(lParam), HIWORD(lParam)/3,
  105.                        TRUE);
  106.             Status("Draw rect: %d,%d,%d,%d", rc.left, rc.top, rc.right, rc.bottom);
  107.  
  108.  
  109.         }
  110.         break;
  111.  
  112.     case WM_COMMAND:
  113.         Command(hWnd, wParam, lParam); 
  114.         break;
  115.  
  116.     case WM_MEASUREITEM:
  117.         MeasureStatusItem(hWnd, (LPMEASUREITEMSTRUCT)lParam);
  118.         return (LRESULT) TRUE;
  119.  
  120.     case WM_DRAWITEM:
  121.         DrawStatusItem(hWnd, (LPDRAWITEMSTRUCT) lParam);
  122.         break;
  123.  
  124.     case WM_PAINT:
  125.         BeginPaint(hWnd, &ps);
  126.         Paint(hWnd, ps.hdc);
  127.         EndPaint(hWnd, &ps);
  128.         break;
  129.  
  130.     case WM_DESTROY:
  131.         UninitializeDDE();
  132.         PostQuitMessage(0);
  133.         break;
  134.  
  135.     default:
  136.         return DefWindowProc(hWnd, msg, wParam, lParam);
  137.         break;
  138.     }
  139.     return NULL;
  140. }
  141.  
  142. static void Command(HWND hWnd, WPARAM wParam, LPARAM lParam) 
  143. {
  144.     switch (wParam) {
  145.     case IDM_EXIT:
  146.         PostMessage(hWnd, WM_CLOSE, 0, 0l);
  147.         break;
  148.  
  149.     default:
  150.         break;
  151.     }
  152. }
  153.  
  154. //
  155. // Paint the main window 
  156. //
  157.  
  158. static void Paint(HWND hWnd, HDC hDC)
  159. {
  160.     RECT rc;
  161.  
  162.     //
  163.     // Just draw a line to separate the status window
  164.     //
  165.  
  166.     GetClientRect(hWnd, &rc);
  167.     MoveTo(hDC, rc.left, rc.bottom*2/3-1);
  168.     LineTo(hDC, rc.right, rc.bottom*2/3-1);
  169.  
  170. }
  171.